import React from "react";
import { NavLink, Routes, Route } from "react-router-dom";

const Home = () => {
  return <div>这是home页面</div>;
};

const About = () => {
  return <div>这是about页面</div>;
};

const App = () => {
  return (
    <>
      <h2>react-router-v6-导航高亮</h2>
      <ul>
        <li>
          {/* activeClassName属性没有了 */}
          {/* 需要使用函数， 参数可以解构isActive， 表示当前的NavLink是否被选中 */}
          <NavLink
            to="/home"
            className={({ isActive }) => (isActive ? "select" : "")}
          >
            home
          </NavLink>
        </li>
        <li>
          <NavLink
            to="/about"
            className={({ isActive }) => (isActive ? "select" : "")}
          >
            about
          </NavLink>
        </li>
      </ul>

      <hr />

      <Routes>
        <Route path="/home" element={<Home />}></Route>
        <Route path="/about" element={<About />}></Route>
        <Route path="*" element={<div>404 font found...</div>}></Route>
      </Routes>
    </>
  );
};

export default App;
